package com.merelyb.business.service.affpay;

import com.merelyb.data.service.service.mybatis.bean.affpay.AffpayCommission;
import com.merelyb.data.service.service.mybatis.bean.affpay.AffpayInfo;
import com.merelyb.data.service.service.mybatis.bean.affpay.AffpayPaymentFrequency;
import com.merelyb.data.service.service.mybatis.bean.affpay.AffpayPaymethod;
import com.merelyb.data.service.service.service.affpay.AffpayCommissionService;
import com.merelyb.data.service.service.service.affpay.AffpayInfoService;
import com.merelyb.data.service.service.service.affpay.AffpayPaymentFrequencyService;
import com.merelyb.data.service.service.service.affpay.AffpayPaymethodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by LiM on 2017/12/18.
 */
@Service
public class BusinessAffpayInfoService {
    @Autowired
    AffpayInfoService affpayInfoService;
    @Autowired
    AffpayPaymethodService affpayPaymethodService;
    @Autowired
    AffpayCommissionService affpayCommissionService;
    @Autowired
    AffpayPaymentFrequencyService affpayPaymentFrequencyService;

    /**
     * 根据页面获取数据
     *
     * @param affpayInfo
     * @return
     */
    public List<AffpayInfo> getAffpayInfo(AffpayInfo affpayInfo) {
        return affpayInfoService.queryListByLimit(affpayInfo);
    }

    /**
     * 获取相关个数
     *
     * @param affpayInfo
     * @return
     */
    public int getAffpayNum(AffpayInfo affpayInfo) {
        return affpayInfoService.getCount(affpayInfo);
    }

    /**
     * 获取所有支付类型
     *
     * @param affpayPaymethod
     * @return
     */
    public List<String> getPayMethodType(AffpayPaymethod affpayPaymethod) {
        List<String> resultList = new ArrayList<>();
        try {
            List<String> affpayPaymethodList = affpayPaymethodService.getAllPayMethods(affpayPaymethod);
            if(affpayPaymethodList != null && affpayPaymethodList.size() > 0){
                resultList.addAll(affpayPaymethodList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return resultList;
        }
    }

    /**
     * 获取所有满足条件的编号
     * @param affpayPaymethod
     * @return
     */
    public List<Long> getPayMethodAffpayIds(AffpayPaymethod affpayPaymethod){
        List<Long> resultList = new ArrayList<>();
        try {
            List<AffpayPaymethod> affpayPaymethodList = affpayPaymethodService.queryAllList(affpayPaymethod);
            for (AffpayPaymethod affpayMehtod:affpayPaymethodList
                    ) {
                resultList.add(affpayMehtod.getAffpayId());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            return resultList;
        }

    }

    /**
     * 获取所有任务类型
     * @param affpayCommission
     * @return
     */
    public List<String> getPayCommissionType(AffpayCommission affpayCommission){
        List<String> resultList = new ArrayList<>();
        try {
            List<String> affpayCommissionList = affpayCommissionService.getAffpayCommission(affpayCommission);
            if(affpayCommissionList!= null && affpayCommissionList.size() > 0){
                resultList.addAll(affpayCommissionList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            return resultList;
        }
    }

    /**
     * 获取所有满足条件的编号
     * @param affpayCommission
     * @return
     */
    public List<Long> getPayCommissionAffpayIds(AffpayCommission affpayCommission){
        List<Long> resultList = new ArrayList<>();
        try {
            List<AffpayCommission> affpayCommissionList = affpayCommissionService.queryAllList(affpayCommission);
            if(affpayCommissionList!= null && affpayCommissionList.size() > 0){
                for (AffpayCommission affpayComm: affpayCommissionList
                        ) {
                    resultList.add(affpayComm.getAffpayId());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            return resultList;
        }

    }

    /**
     * 获取所有周期类型
     * @param affpayPaymentFrequency
     * @return
     */
    public List<String> getPayFreType(AffpayPaymentFrequency affpayPaymentFrequency){
        List<String> resultList = new ArrayList<>();
        try {
            List<String> affpayPaymentFrequencyList = affpayPaymentFrequencyService.getAffpayPaymentFreType(affpayPaymentFrequency);
            if(affpayPaymentFrequencyList != null && affpayPaymentFrequencyList.size() > 0){
                resultList.addAll(affpayPaymentFrequencyList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            return resultList;
        }
    }


    /**
     * 获取所有满足条件的编号
     * @param affpayPaymentFrequency
     * @return
     */
    public List<Long> getPayFreAffpayIds(AffpayPaymentFrequency affpayPaymentFrequency){
        List<Long> resultList = new ArrayList<>();
        try {
            List<AffpayPaymentFrequency> affpayPaymentFrequencyList = affpayPaymentFrequencyService.queryAllList(affpayPaymentFrequency);
            if(affpayPaymentFrequencyList != null && affpayPaymentFrequencyList.size() > 0){
                for (AffpayPaymentFrequency affpayFre: affpayPaymentFrequencyList
                        ) {
                    resultList.add(affpayFre.getAffpayId());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            return resultList;
        }
    }

    /**
     * 获取所有最小支付
     * @param affpayInfo
     * @return
     */
    public List<String> getPayMinType(AffpayInfo affpayInfo){
        List<String> resultList = new ArrayList<>();
        try {
            List<String> affpayInfoList = affpayInfoService.getMinPayType(affpayInfo);
            if(affpayInfoList!= null && affpayInfoList.size() > 0){
                resultList.addAll(affpayInfoList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            return resultList;
        }
    }

    /**
     * 获取所有符合条件的编号
     * @param affpayInfo
     * @return
     */
    public List<Long> getPayMinAffpayIds(AffpayInfo affpayInfo){
        List<Long> resultList = new ArrayList<>();
        try {
            List<AffpayInfo> affpayInfoList = affpayInfoService.queryAllList(affpayInfo);
            if(affpayInfoList!= null && affpayInfoList.size() > 0){
                for (AffpayInfo affpay: affpayInfoList
                        ) {
                    resultList.add(affpay.getId());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            return resultList;
        }
    }

    /**
     * 根据编号获取数据
     * @param IdsList
     * @return
     */
    public List<AffpayInfo> getAffpayInfoByIds(List<Long> IdsList){
        List<AffpayInfo> resultList = null;
        try {
            resultList = affpayInfoService.getAffpayInfoByIds(IdsList);

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            return resultList;
        }
    }

}
